package cn.edu.ctbu.datajpa_02.service;

import cn.edu.ctbu.datajpa_02.domain.Teacher;
import cn.edu.ctbu.datajpa_02.repository.TeacherRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherService {

    @Autowired
    private TeacherRepository teacherRepository;

    public List<Teacher> findAll() {
        return teacherRepository.findAll();
    }

    /**
     *  按id进行查询
     * @param id 主键，整数
     * @return
     */
    public Teacher findById(Integer id) {
        return teacherRepository.findById(id).orElse( null);
    }

    /***
     *  查询
     *  找出工号最晚进校的所有教师
     */
    public List<Teacher> getLatestJoinedTeachers(){
        return teacherRepository.getLatestJoinedTeachers();
    }

    /***
     *  插入
     *  插入职工信息
     */
    public void insert(Teacher student) {
        teacherRepository.save(student);
    }

    /***
     *  更新
     *  更新职工信息
     */
    public void update(Teacher student) {

        teacherRepository.save(student);
    }

    /***
     *  删除
     *  删除职工信息
     */
    public void delete(Integer id) {
        teacherRepository.deleteById(id);
    }
}
